#-------------------------------------------------------------------------------
# Name:        settings
# Purpose:
#
# Author:      Pablo
#
# Created:     22/04/2012
# Copyright:   (c) Monxcleyr Productions 2012
# Licence:     GPL v3
#-------------------------------------------------------------------------------
#!/usr/bin/env python

import config, os, pygame

class settings():
  """  """

  def __init__(self, filename):
    self.filename = filename
    self.conf = config.Config()
    # Load up ini file
    self.conf.read(os.path.join(self.filename))

  def load(self):

    self.res_setting = self.conf.getint('Graphics', 'res_setting')
    self.fullscreen = self.conf.getboolean('Graphics', 'fullscreen')
    self.music_volume = self.conf.getint('Sounds', 'music_volume')
    self.sound_volume = self.conf.getint('Sounds', 'sound_volume')
    self.music = self.conf.getboolean('Sounds', 'music')
    self.sounds = self.conf.getboolean('Sounds', 'sounds')

  def activate(self):

    music_volume = self.music_volume * .01
    if self.music == True:
      pygame.mixer.music.set_volume(music_volume)
    else:
      pygame.mixer.music.set_volume(0)

##    sound_volume = self.sound_volume * .01
##    if self.sounds == True:
##      pygame.mixer.Sound.set_volume(music_volume)
##    else:
##      pygame.mixer.Sound.set_volume(0)

  def save(self):

    self.conf.set('Graphics', 'res_setting', str(self.res_setting))
    self.conf.set('Graphics', 'fullscreen', str(self.fullscreen))
    self.conf.set('Sounds', 'music_volume', str(self.music_volume))
    self.conf.set('Sounds', 'sound_volume', str(self.sound_volume))
    self.conf.set('Sounds', 'music', str(self.music))
    self.conf.set('Sounds', 'sounds', str(self.sounds))

    with open(os.path.join(self.filename), 'w') as configfile:
      self.conf.write(configfile)
